{include file='common/_meta' /}
<style>
table td .layui-table-cell,table th .layui-table-cell {
    padding: 0 5px;

}
/*.layui-table-cell .huizong{
    color: #e00;
}*/
</style>
<body>
<div class="container">
	<div class="layui-row">
        <div class="layui-col-md12 breadcrumb">
    		<span class="layui-breadcrumb">
    			<a><cite>报表管理</cite></a>
    			<a><cite>月报表</cite></a>
    		</span>
        </div>
    </div>

    <div class="layui-row">

    	<form class="layui-form" action="" lay-filter="" style="padding-top: 15px;">
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">报表时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="seletime" value="" autocomplete="off" placeholder="" class="layui-input" id="seletime">
                    </div>
                </div>
            </div>
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">查询账号：</label>
                    <div class="layui-input-block">
                        <select name="cha" id="cha" lay-verify="" lay-search>
                            <option value="">全部</option>
                            {volist name="bus_channel" id="c"}
                            <option value="{$c.channel_id}">{$c.company_name}-{$c.channel_id}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn custom-sm-fluid" lay-submit lay-filter="custom-search">搜索</button>
                    </div>
                </div>
            </div>

            <div class="layui-col-sm12">
                <p class="gettime"></p>
            </div>

    	</form>

    </div>

	<div class="layui-col-md12">

		<table class="layui-hide" id="initdate" lay-filter="datatable"></table>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">

                <button class="layui-btn custom-sm-fluid" onclick="update_yue()">更新</button>

            </div>
        </script>
        <script type="text/html" id="barDemo">
            {{# if(d.isp_host == '汇总' && d.company_name != '汇总' ){ }}
          	<a class="" lay-event="details"><i class="layui-icon layui-icon-file-b"></i></a>
            {{# } }}
        </script>

	</div>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{:$Think.config.__STATIC__}/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
var tableIns;
layui.config({
    //配置 layui 第三方扩展组件存放的基础目录
    base: '/static/layui_exts/'
}).extend({
    tableMerge: 'tableMerge/tableMerge'
}).use(['layer', 'form', 'table', 'laydate', 'tableMerge'], function() {

    var table   = layui.table;
    var layer   = layui.layer;
    var form    = layui.form;
    var laydate = layui.laydate;
    var tableMerge = layui.tableMerge;

    laydate.render({
        elem: '#seletime'
        ,type: 'month'
        ,value: '{$request['seletime']}'
    });

    tableIns = table.render({
        elem: '#initdate'
        ,toolbar: '#toolbarDemo'//默认工具栏, width: 100,fixed:'left'
        ,url:'{:url('OrderReport/indexYue')}'
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,method:'post'//请求方式
        ,page:false//开启分页
        ,limit:1000000//每页记录数
        ,totalRow: false
        ,height: 'full-150'
        ,cols: [[
            {field:'company_name',merge: ['cid','company_name'], title: '用户', totalRowText: '汇总'}
            ,{field:'create_time', title: '日期', totalRow: true, minWidth: 140      ,templet: function(d){
                if(d.company_name == '汇总' || d.isp_host == '汇总'){
                    return '<span class="huizong">汇总</span>'
                }else{
                    return '<span>'+d.create_time+'</span>';
                }
            }}
            ,{field:'sms_all', title: '短信总量', totalRow: true, minWidth: 140}
            ,{field:'sms_success', title: '成功短信', totalRow: true, minWidth: 140}
            ,{field:'sms_faild', title: '失败短信', totalRow: true, minWidth: 140}
            ,{field:'sms_sending', title: '发送中短信', totalRow: true, minWidth: 140}
            ,{field:'amt_sms_success', title: '总金额', totalRow: true, minWidth: 120,style:"text-align: right"}
            {if condition="session('user_type') == 'admin'"}
            ,{fixed:'right', title: '操作', toolbar: '#barDemo', width: 40, unresize: true}
            {/if}
        ]]
        ,done: function(res, curr, count){
            laydate.render({elem: '#seletime',type: 'month',value: res.msg});
            tableMerge.render(this)
            $(".huizong").each(function(){
                $(this).parent().parent().parent().css("background","#d2fffb");
                // $(this).parent().parent().parent().find('td').eq(0).css("background","#fff");
            })
        }
    });

    //监听工具条
  	table.on('tool(datatable)', function(obj) {

        var data = obj.data;

        switch(obj.event) {

            case 'details':
                layer.open({
                    type: 2,
                    title: '详情',
                    area: ['100%', '100%'],
                    content: "{:url('OrderReport/channelIndexYue')}?cid=" + data.cid  + "&seletime=" + $("#seletime").val()
                });

                break;
        }
    });

    // 监听搜索事件
    form.on('submit(custom-search)', function(data) {

        tableIns.reload({
            where: data.field
        });

        $(window).resize()

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    $(".huizong").each(function(){
        // $(this).parent('tr').children("td").css("background","#e00");
        alert($(this).html());
    })
});
  	// 更新事件
    function update_yue(){

        var index = layer.load(2);

        $.post('{:url('OrderReport/UpdateYue')}',{seletime: $("#seletime").val()},function(e){

            layer.close(index);

            if(e > 0)
            {
                alert("请"+e+"秒后再试");
            }
          	tableIns.reload({
            	where: {
    	          	seletime: $("#seletime").val()
            	}
          	});
        })

        $(window).resize()

      	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>